using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace VirtualBlocks
{
    public class Display : DrawableGameComponent
    {
        public String DisplayText { get; set; }
        public RenderTarget2D leftEye;
        public RenderTarget2D rightEye;
        public RenderTarget2D center;
        public Effect anaglyphEffect;
        public QuadRenderer quad;
        public float AnaglyphDistance = 0.009f;

        private ContentManager content;
        private SpriteBatch spriteBatch;
        private SpriteFont font;
        private int bbWidth, bbHeight;

        public Display(Game game)
            : base(game)
        {
            content = new ContentManager(game.Services);
            this.DisplayText = "Mouse (Move) position: ";
        }

        private void GraphicsDevice_DeviceReset(object sender, EventArgs e)
        {
            bbWidth = GraphicsDevice.PresentationParameters.BackBufferWidth;
            bbHeight = GraphicsDevice.PresentationParameters.BackBufferHeight;
        }
                
        protected override void LoadContent()
        {	
            leftEye = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
            center = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
            rightEye = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
            anaglyphEffect = content.Load<Effect>("Content/ShaderEffect");
            quad = new QuadRenderer(GraphicsDevice);

            this.GraphicsDevice.DeviceReset +=new EventHandler<EventArgs>(GraphicsDevice_DeviceReset);
            GraphicsDevice_DeviceReset(null, null);

            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = content.Load<SpriteFont>("Content/font1");
        }

        protected override void UnloadContent()
        {
            content.Unload();
        }

        public override void Update(GameTime gameTime)
        {            
        }
        
        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();
            if (!string.IsNullOrEmpty(DisplayText))
                spriteBatch.DrawString(font, DisplayText, new Vector2(10,10), Color.DarkSlateBlue);
            spriteBatch.End();
        }

    }
}
